#!/usr/bin/env python
# coding: utf-8

# # 第12周 Python知识点总结

# ## 自我评估

# In[21]:


python_base = {
    "Python_introduction": {
        "Python_history": "100(80)",
        "编程语言": {
            "分类": "100(80)",
            "Python 优缺点": "100(80)"}
    },
    "IDE": {
        "IDLE": {
            "操作": "100(90)",
            "意义": "100(90)"
        },
        "Jupyter Notebook": {
            "操作": "100(85)",
            "拓展插件": "100(85)"
        },
        "PyCharm": {
            "操作": "100(90)",
            "界面选项": "100(85)"
        }
    },
    "Anaconda": {
        "安装、配置与使用": "100(90)",
        "意义": "100(88)"
    },
    "标准库": {
        "分类": "100(83)",
        "调用": "100(80)"
    },
    "流程控制语句": {
        "条件语句": {
            "if 语句": "100(90)",
            "else 语句": "100(75)",
            "elif 语句": "100(70)"
        },
        "循环语句": {
            "while 循环": "100(75)",
            "for 循环": {
                "迭代字符串、列表": "100(65)",
                "迭代指定的次数、内置函数range()": "100(65)"
            }
        },
        "循环嵌套": "100(65)"
    },
    "变量": {
        "赋值": "100(95)",
        "数据类型": {
            "数字": {
                "整型、浮点、（复数）": "100(70)",
                "大小比较": "100(75)",
                "运算": "100(75)"
            },
            "字符串": {
                "单/双/三引号": "100(95)",
                "转义": "100(85)",
                "占位符与 format() ": "100(75)",
                "拼接": "100(80)",
                "split()": "100(85)",
                "其他字符串内置函数": "100(70)"
            },
            "布尔值": "100(65)",
            "数据类型查询与转换": "100(65)"
        },
        "输出与用户输入": "100(75)"
    },
    "代码样式": {
        "PEP 8": "100(70)",
        "注释": "100(95)",
        "变量命名": "100(80)"
    },
    "数据结构": {
        "列表": {
            "操作": {
                "增删改": "100(78)",
                "切片": "100(80)"
            },
            "索引": "100(80)"
        },
        "字典": {
            "操作": "100(75)",
            "嵌套": "100(65)"
        },
        "元组": "100(80)",
        "集合": "100(85)",
        "数据访问": "100(80)",
        "Pandas": "100(50)",
    },
    "函数": {
        "定义": "100(80)",
        "使用": {
            "实参、形参": {
                "位置参数": "100(80)",
                "关键字参数": "100(80)",
                "默认值": "100(80)"
            }
        },
        "返回值": "100(80)",
        "模块": {
            "意义": "100(85)",
            "封装与调用": "100(60)",
        }
    }
}


# ## 知识点总结
# ### 集合

# In[22]:


group = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
print(group)                    


# #### 添加元素

# In[23]:


group = set(("Taylor", "Anna", "Aries"))
group.add("Avril")
print(group)


# #### 移除元素

# In[24]:


group = set(("Taylor", "Anna", "Aries"))
group.discard("Facebook")  # 不存在不会发生错误
print(group)


# #### 计算集合元素个数

# In[25]:


group = set(("Taylor", "Anna", "Aries"))
len(group)


# #### 清空集合

# In[26]:


group = set(("Taylor", "Anna", "Aries"))
group.clear()
print(group)


# #### 判断元素是否在集合中存在

# In[27]:


group = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
print(group)    


# In[28]:


'orange' in group


# In[29]:


'crabgrass' in group


# ### 循环语句
# #### while循环

# In[30]:


n = 100
 
sum = 0
counter = 1
while counter <= n:
    sum = sum + counter
    counter += 1
 
print("1 到 %d 之和为: %d" % (n,sum))


# #### 无限循环

# In[ ]:


var = 1
while var == 1 :  # 表达式永远为 true
   num = int(input("输入一个数字  :"))
   print ("你输入的数字是: ", num)
 
print ("Bye!")


# #### for循环

# In[ ]:


sites = ["Baidu", "Google","Runoob","Taobao"]
for site in sites:
    if site == "Runoob":
        print("菜鸟教程!")
        break
    print("循环数据 " + site)
else:
    print("没有循环数据!")
print("完成循环!")


# #### range()函数

# In[2]:


for i in range(5):
     print(i)


# In[3]:


for i in range(5,9) :
    print(i)


# In[4]:


for i in range(0, 10, 3) :
    print(i)


# In[6]:


a = ['Google', 'Baidu', 'Runoob', 'Taobao', 'QQ']
for i in range(len(a)):
         print(i, a[i])


# In[7]:


list(range(5))


# #### while中使用break

# In[8]:


n = 5
while n > 0:
    n -= 1
    if n == 2:
        break
    print(n)
print('循环结束。')


# #### while中使用continue

# In[ ]:


n = 5
while n > 0:
    n = 1
    if n == 2:
        continue
    print(n)
print('循环结束。')


# ### 列表

# In[ ]:


list = ['red', 'green', 'blue', 'yellow', 'white', 'black']
print( list[0] )
print( list[1] )
print( list[2] )


# In[ ]:


list = ['red', 'green', 'blue', 'yellow', 'white', 'black']
print( list[-1] )
print( list[-2] )
print( list[-3] )


# In[ ]:


nums = [10, 20, 30, 40, 50, 60, 70, 80, 90]
print(nums[0:4])


# In[ ]:


list = ['Google', 'Runoob', "Zhihu", "Taobao", "Wiki"]
 
# 读取第二位
print ("list[1]: ", list[1])
# 从第二位开始（包含）截取到倒数第二位（不包含）
print ("list[1:-2]: ", list[1:-2])


# #### 更新列表

# In[ ]:


list = ['Google', 'Runoob', 1996, 2000]
 
print ("第三个元素为 : ", list[2])

list[2] = 2001
print ("更新后的第三个元素为 : ", list[2])


# #### 删除列表元素

# In[ ]:


list = ['Google', 'Runoob', 1997, 2000]
 
print ("原始列表 : ", list)

del list[3]

print ("删除第三个元素 : ", list)


# ### 字典
# #### 访问字典里的值

# In[ ]:


dict = {'Name': 'laoyou', 'Age': 30, 'Class': 'First'}
 
print ("dict['Name']: ", dict['Name'])
print ("dict['Age']: ", dict['Age'])


# #### 修改字典

# In[ ]:


dict = {'Name': 'laoyou', 'Age': 30, 'Class': 'First'}
 
dict['Age'] = 8               # 更新 Age
dict['School'] = "中山大学南方学院"  # 添加信息
 
 
print ("dict['Age']: ", dict['Age'])
print ("dict['School']: ", dict['School'])


# ### 函数

# In[ ]:


def hello() :
    print("Hello World!")

hello()


# In[ ]:


def max(a, b):
    if a > b:
        return a
    else:
        return b
 
a = 4
b = 5
print(max(a, b))


# In[ ]:


# 计算面积函数
def area(width, height):
    return width * height
 
def print_welcome(name):
    print("Welcome", name)
 
print_welcome("Aries")
w = 4
h = 5
print("width =", w, " height =", h, " area =", area(w, h))


# #### 函数调用

# In[ ]:


# 定义函数
def printme( str ):
   # 打印任何传入的字符串
   print (str)
   return
 
# 调用函数
printme("我要调用用户自定义函数!")
printme("再次调用同一函数")


# #### 关键字参数

# In[ ]:


#可写函数说明
def printme( str ):
   "打印任何传入的字符串"
   print (str)
   return
 
#调用printme函数
printme( str = "雷猴")


# In[ ]:


#可写函数说明
def printinfo( name, age ):
   "打印任何传入的字符串"
   print ("名字: ", name)
   print ("年龄: ", age)
   return
 
#调用printinfo函数
printinfo( age=19, name="Aries" )


# #### 默认参数

# In[20]:


#可写函数说明
def printinfo( name, age = 35 ):
   "打印任何传入的字符串"
   print ("名字: ", name)
   print ("年龄: ", age)
   return
 
#调用printinfo函数
printinfo( age=19, name="Aries" )
print ("------------------------")
printinfo( name="runoob" )

